<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 查询区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        <!-- <a-button type="primary" icon="download" @click="handleExportXls('订单表')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-form-item label="是否强制更新" style="margin-right: 10px">
            <a-select
              v-model="queryParam.isForceUpdate"
              style="width: 120px"
              :options="[
                { label: '否', value: '0' },
                { label: '是', value: '1' },
              ]"
              allowClear
              placeholder="请选择"
            />
          </a-form-item>
          <a-form-item label="系统类型" style="margin-right: 10px">
            <a-select
              v-model="queryParam.osType"
              style="width: 120px"
              :options="[
                { label: 'ios', value: '0' },
                { label: '安卓', value: '1' },
              ]"
              allowClear
              placeholder="请选择"
            />
          </a-form-item>
          <a-form-item label="应用渠道类型" style="margin-right: 10px">
            <a-select
              v-model="queryParam.terminalType"
              style="width: 120px"
              :options="[
                { label: '技师端', value: '0' },
                { label: '客户端', value: '1' },
              ]"
              allowClear
              placeholder="请选择"
            />
          </a-form-item>
          <a-form-item label="版本号" style="margin-right: 10px">
            <a-input placeholder="请输入版本号" v-model="queryParam.appVersion"></a-input>
          </a-form-item>
          <a-form-item label="版本名称" style="margin-right: 10px">
            <a-input placeholder="请输入版本名称" v-model="queryParam.appVersionName"></a-input>
          </a-form-item>
          <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
          </span>
        </a-form>
      </div>
    </div>
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <a-table
      ref="table"
      size="default"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      @change="handleTableChange"
    >
      <span slot="evaluateType" slot-scope="text, record">
        <a-rate v-model="record.evaluateType" />
      </span>
      <span slot="action" slot-scope="text, record">
        <a @click="handleEdit(record)">编辑</a>

        <a-divider type="vertical" />
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
          <a>删除</a>
        </a-popconfirm>
      </span>
    </a-table>
    <xhdjVersionControlModal ref="modalForm" @ok="modalFormOk"></xhdjVersionControlModal>
  </a-card>
</template>

<script>
import { filterObj } from '@/utils/util'
import { getAction, putAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import xhdjVersionControlModal from './modules/xhdjVersionControlModal.vue'
export default {
  name: 'xhdjVersionControlList',
  mixins: [JeecgListMixin],
  components: {
    xhdjVersionControlModal,
  },
  data() {
    return {
      description: '评价列表',
      queryParam: {},
      columns: [
        {
          title: '版本号',
          align: 'center',
          dataIndex: 'appVersion',
        },
        {
          title: '版本名称',
          align: 'center',
          dataIndex: 'appVersionName',
        },
        {
          title: '更新内容',
          align: 'center',
          dataIndex: 'description',
        },
        {
          title: '下载地址',
          align: 'center',
          dataIndex: 'downloadUrl',
        },
        {
          title: '是否强制更新',
          align: 'center',
          dataIndex: 'isForceUpdate',
          customRender: function (type) {
            if (type == '0') {
              return '否'
            } else {
              return '是'
            }
          },
        },
        {
          title: '系统类型',
          align: 'center',
          dataIndex: 'osType',
          customRender: function (type) {
            if (type == '0') {
              return 'ios'
            } else {
              return '安卓'
            }
          },
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '发布时间',
          align: 'center',
          dataIndex: 'releaseDate',
        },
        {
          title: '应用渠道类型',
          align: 'center',
          dataIndex: 'terminalType',
          customRender: function (type) {
            if (type == '0') {
              return '技师端'
            } else {
              return '客户端'
            }
          },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/basics/xhdjVersionUpdates/list',
        editCementSend: '/message/read',
        readAllMsg: '/message/allRead',
        delete: '/basics/xhdjVersionUpdates/delete',
        deleteBatch: '/order/xhdjOrderEvaluate/deleteBatch',
      },
      loading: false,
      openPath: '',
      formData: '',
    }
  },
  methods: {
    handleDetail: function (record) {
      this.$refs.sysAnnouncementModal.detail(record)
      this.$refs.sysAnnouncementModal.title = '查看'
    },
    showAnnouncement(record) {
      var that = this
      getAction(this.url.editCementSend, { id: record.id }).then((res) => {
        that.$message.success(res.message)
        that.loadData()
        that.syncHeadNotic()
      })
      // if (record.openType === 'component') {
      //   this.openPath = record.openPage
      //   this.formData = { id: record.busId }
      //   this.$refs.showDynamNotice.detail()
      // } else {
      //   this.$refs.ShowAnnouncement.detail(record)
      // }
    },
    syncHeadNotic(anntId) {
      getAction('sys/annountCement/syncNotic', { anntId: anntId })
    },
    readAll() {
      var that = this
      that.$confirm({
        title: '确认操作',
        content: '是否全部标注已读?',
        onOk: function () {
          getAction(that.url.readAllMsg).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.loadData()
              that.syncHeadNotic()
            }
          })
        },
      })
    },
  },
}
</script>
<style scoped>
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
.ant-form {
  display: flex;
}
</style>
